package com.mycompany.oj.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Aspect
@Component
public class Parse {

    @Pointcut("@annotation(com.mycompany.oj.aspect.ParseToken)")
    public void GetUsername() {
    }


    @Before("GetUsername()")
    public String doBefore(JoinPoint joinPoint) throws Throwable {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//        Object args[] = joinPoint.getArgs();
        Object admin = request.getParameter("username");
        System.out.println(admin);
        request.setAttribute("username",admin+"aaaa");
        return admin.toString() + "aaaaaaaa";
    }
}
